﻿//using System;
//using System.Collections.Generic;
//using System.Data;
//using System.Linq;
//using System.Threading.Tasks;
//using Dapper;

//namespace NiuX.Dapper.Dapper;

///// <summary>
///// 非泛型 Dapper 仓储
///// </summary>
//public partial class DapperRepository : IDapperRepository, IDisposable, IAsyncDisposable
//{
//    /// <summary>
//    /// 数据库连接对象
//    /// </summary>
//    private readonly IDbConnection _db;

//    /// <summary>
//    /// 服务提供器
//    /// </summary>
//    private readonly IServiceProvider _serviceProvider;

//    /// <summary>
//    /// 构造函数
//    /// </summary>
//    /// <param name="serviceProvider"></param>
//    /// <param name="db"></param>
//    public DapperRepository(
//        IServiceProvider serviceProvider
//        , IDbConnection db)
//    {
//        _serviceProvider = serviceProvider;
//        _db = db;
//    }

//    /// <summary>
//    /// 连接上下文
//    /// </summary>
//    public virtual IDbConnection DbConnection
//    {
//        get
//        {
//            if (_db.State != ConnectionState.Open) _db.Open();
//            return _db;
//        }
//    }


//    /// <summary>
//    /// 查询返回动态类型
//    /// </summary>
//    /// <param name="sql"></param>
//    /// <param name="param"></param>
//    /// <param name="transaction"></param>
//    /// <param name="buffered"></param>
//    /// <param name="commandTimeout"></param>
//    /// <param name="commandType"></param>
//    /// <returns></returns>
//    public virtual IEnumerable<dynamic> Query(string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null)
//    {
//        return DbConnection.Query(sql, param, transaction, buffered, commandTimeout, commandType);
//    }

//    public List<dynamic> QueryAsList(string sql, object param = null, IDbTransaction transaction = null,
//        bool buffered = true,
//        int? commandTimeout = null, CommandType? commandType = null) =>
//        Query(sql, param, transaction, buffered, commandTimeout, commandType).ToList();

//    /// <summary>
//    /// 查询返回特定类型
//    /// </summary>
//    /// <typeparam name="T"></typeparam>
//    /// <param name="sql"></param>
//    /// <param name="param"></param>
//    /// <param name="transaction"></param>
//    /// <param name="buffered"></param>
//    /// <param name="commandTimeout"></param>
//    /// <param name="commandType"></param>
//    /// <returns></returns>
//    public virtual IEnumerable<T> Query<T>(string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null)
//    {
//        return DbConnection.Query<T>(sql, param, transaction, buffered, commandTimeout, commandType);
//    }

//    /// <summary>
//    /// 查询返回动态类型
//    /// </summary>
//    /// <param name="sql"></param>
//    /// <param name="param"></param>
//    /// <param name="transaction"></param>
//    /// <param name="commandTimeout"></param>
//    /// <param name="commandType"></param>
//    /// <returns></returns>
//    public virtual Task<IEnumerable<dynamic>> QueryAsync(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
//    {
//        return DbConnection.QueryAsync(sql, param, transaction, commandTimeout, commandType);
//    }

//    /// <summary>
//    /// 查询返回特定类型
//    /// </summary>
//    /// <typeparam name="T"></typeparam>
//    /// <param name="sql"></param>
//    /// <param name="param"></param>
//    /// <param name="transaction"></param>
//    /// <param name="commandTimeout"></param>
//    /// <param name="commandType"></param>
//    /// <returns></returns>
//    public virtual Task<IEnumerable<T>> QueryAsync<T>(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
//    {
//        return DbConnection.QueryAsync<T>(sql: sql, param, transaction, commandTimeout, commandType);
//    }

//    /// <summary>
//    /// 执行命令
//    /// </summary>
//    /// <param name="sql"></param>
//    /// <param name="param"></param>
//    /// <param name="transaction"></param>
//    /// <param name="commandTimeout"></param>
//    /// <param name="commandType"></param>
//    /// <returns></returns>
//    public virtual int Execute(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
//    {
//        return DbConnection.Execute(sql, param, transaction, commandTimeout, commandType);
//    }

//    /// <summary>
//    /// 执行命令
//    /// </summary>
//    /// <param name="sql"></param>
//    /// <param name="param"></param>
//    /// <param name="transaction"></param>
//    /// <param name="commandTimeout"></param>
//    /// <param name="commandType"></param>
//    /// <returns></returns>
//    public virtual Task<int> ExecuteAsync(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
//    {
//        return DbConnection.ExecuteAsync(sql, param, transaction, commandTimeout, commandType);
//    }


//    public void Dispose()
//    {
//        _db.Dispose();
//    }

//    public async ValueTask DisposeAsync()
//    {
//        if (_db is IAsyncDisposable disposable)
//        {
//            await disposable.DisposeAsync();
//        }
//    }
//}


